package com.atguigu.tingshu.search.receiver;

import cn.hutool.core.util.StrUtil;
import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.search.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author xiaoxu
 * @description:
 * @date 2024/08/26 13:51
 **/
@Slf4j
@Component
public class SearchReceiver {

    @Autowired
    private SearchService searchService;


    @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_UPPER)
    public void upperAlbum(ConsumerRecord<String,String> record){
        String value = record.value();
        if (StrUtil.isNotBlank(value)){
            log.info("[专辑搜索服务接到消息,专辑上架id为:{}",value);
            searchService.upperAlbum(Long.valueOf(value));
        }

    }

    @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_LOWER)
    public void lowerAlbum(ConsumerRecord<String,String> record){
        String value = record.value();
        if (StrUtil.isNotBlank(value)){
            log.info("[专辑搜搜服务接到消息,专辑下架id为:{}",value);
            searchService.lowerAlbum(Long.valueOf(value));
        }

    }

}
